const config = require('../config');
const httpUtil = require('../utils/http-utils');
let http = new httpUtil(config.httpUrl());

module.exports = {
    //获取token
    reqgetAccessToken: () => {
        return new Promise((resolve, reject) => {
            let params = { grant_type: 'password', auth_type: 'bigScreen', loginKey: (Buffer.from('bigScreenToken' + parseInt(new Date().getTime()))).toString('base64') }
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //调用叫号
//     叫号取餐:callTakeFood
// 入参：storeId,deviceId
    reqcallTakeFood: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'callTakeFood' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //用户扫码出餐完成,更新菜品状态
    reqresponseInstructionResult: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'responseInstructionResult' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //用户扫码出餐完成,更新菜品状态
    requpdateProductStatus: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'updateProductStatus' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //冷库库存减少 (备餐完成减少库存)
    reqchangeFreezerStock: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'changeFreezerStock' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //修改保温柜库存 (放餐+1, 出餐-1)
    reqchangeThermotankStock: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'changeThermotankStock' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取门店信息
    reqgetStores: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getStores' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取设备信息
    reqgetDevices: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getDevices' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取菜品信息
    reqgetProducts: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getProducts' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取冷柜库存
    reqgetFreezerStock: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getFreezerStock' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取保温柜库存
    reqgetThermotankStock: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getThermotankStock' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //校验二维码数据
    reqcheckQrCode: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'checkQrCode' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取保温柜出餐位置getThermotankTakePlace
    reqgetThermotankTakePlace: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getThermotankTakePlace' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //获取保温柜放餐位置getThermotankGivePlace
    reqgetThermotankGivePlace: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'getThermotankGivePlace' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    // removeCallQueueByOrder
    // 取餐完成
    reqremoveCallQueueByOrder: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'removeCallQueueByOrder' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },
    //发送语音
    reqSendTipMessageToVoiceTerminal: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'sendTipMessageToVoiceTerminal' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },

    //用户扫码备餐
    reqCookClaypotByScheduleSystem: (param = {}) => {
        return new Promise((resolve, reject) => {
            let params = { sysAppName: 'business', service: 'Claypot2CommonService', method: 'cookClaypotByScheduleSystem' }
            Object.assign(params, param)
            http.post(params, (err, res, body) => { if (err) { console.log(err); reject(err) } else { resolve(JSON.parse(body)) } });
        })
    },

}